Constructing Data Reference Handles
How do you construct a data reference handle? As stated above, the information that identifies the data is specified in the data reference handle (while the type of the data reference is specified in the data reference type). Here's how to construct data reference handles for the various data references:
Alias Data Reference Handle
The alias handle data reference handle is a standard Macintosh alias handle (see Inside Macintosh:Files for more information). Here's code showing how to construct the data reference handle for an alias data reference. In our example, you pass a standard Macintosh file system specification record for the desired file in the theFile parameter and an alias handle is returned. We use the NewAlias function to create the alias handle, but you can also use any of the other Alias Manager functions which return an alias handle (QTNewAlias , NewAliasMinimal , NewAliasMinimalFromFullPath , etc.):
Handle MyCreateAliasDataReferenceHandle(FSSpec *theFile)
{
OSErr err;
AliasHandle theAlias;
err = NewAlias(nil, theFile, &theAlias);
if (err == noErr)
{
return (Handle)theAlias;
}
return nil;
}
Handle Data Reference Handle
The handle data reference handle is a Macintosh handle whose data is the handle containing the actual data. Here's code showing how to construct the data reference handle for a handle data reference. In our example, you simply pass a handle to your actual data in the theDataH parameter and a data reference handle is returned:
Handle MyCreateDataReferenceHandle(Handle theDataH)
{
Handle dataRef = nil;
OSErr err;
// create a data reference handle for our data
err = PtrToHand( &theDataH, &dataRef, sizeof(Handle));
return dataRef;
}
Note: most QuickTime functions which accept data references accept the data reference handle and data reference type as separate parameters. For example, here's how you would pass a handle data reference to the Graphics Importer function GetGraphicsImporterForDataRef :
void MyGetGraphicsImporterForDataRef(Handle ourData)
{
OSErr err;
ComponentInstance gi;
Handle dataRefH = nil;
dataRefH = MyCreateDataReferenceHandle(ourData);
if (dataRefH)
{
err = GetGraphicsImporterForDataRef (
dataRefH, /* data reference */
HandleDataHandlerSubType, /* data ref type */
&gi);
/* ...now use the returned graphics importer component
gi as you please... */
/* close the graphics importer component instance when
we are done */
CloseComponent(gi);
}
/* clean up our data reference handle when we
are done */
if (dataRefH)
{
DisposeHandle(dataRefH);
}
}
Note: you would need to dispose of the data reference handle when you are done.
URL Data Reference Handle
The url data reference handle is a handle whose data is a C-string (null-terminated) specifying a url. Here's code showing how to construct the data reference handle for a url data reference:
Handle MyCreateURLDataReferenceHandle()
{
char url[] = "rtsp://www.mycompany.com/mymovie.mov";
Handle urlDataRef;
OSErr err;
urlDataRef = NewHandleClear(StrLength(url) + 1);
if ( ( err = MemError()) != noErr) goto bail;
BlockMoveData(url, *urlDataRef, StrLength(url) + 1);
return (urlDataRef);
bail:
DisposeHandle(urlDataRef);
return nil;
}
Resource Data Reference Handle
The resource data reference handle is also a Macintosh alias handle. However, appended to the end of the alias handle is the resource type (stored as a 32-bit unsigned integer) and ID (stored as a 16-bit signed integer) to use within the specified file. These values must be big-endian format.
Here's code showing how to construct the data reference handle for a resource data reference. In our example, we build a data reference for a standard QuickTime movie file whose movie resource resides in the resource fork of the file. Pass a standard Macintosh file system specification record for the desired movie file in the theFile parameter. Next, an alias handle is created for this file. Finally, we append to this alias handle the resource type for the movie resource (type 'moov' ) along with the movie resource ID (128). Once this information is appended, the completed resource data reference handle is returned.
Note you can use any of the other Alias Manager functions to create the alias handle (QTNewAlias , NewAliasMinimal , NewAliasMinimalFromFullPath , etc.):
Handle MyCreateResourceDataReferenceHandle(FSSpec *theFile)
{
OSErr err;
AliasHandle theAlias;
err = NewAlias(nil, theFile, &theAlias);
if (err == noErr)
{
OSType ourType = EndianU32_NtoB(MovieResourceType);
short ourID = EndianU16_NtoB(128);
/* append resource type */
err = PtrAndHand(&ourType, (Handle)theAlias, sizeof(OSType));
/* append resource id */
err = PtrAndHand(&ourID, (Handle)theAlias, sizeof(short));
return (Handle)theAlias;
}
return nil;
}
Back to top
Data Reference Extensions
One can certainly construct a handle data reference for a given piece of data, and use this handle data reference with any of the QuickTime API's which operate on data references. However, if you just construct a "plain" handle data reference, the reference doesn't contain any information about the file type or file name, so QuickTime will end up performing a slow validate search to identify the file (since there's really no other way). As well as being slow, this technique will miss some file formats which can't be detected by validation.
For example, when you call the GetGraphicsImporterForFile function to try to obtain a graphics importer for a given file, QuickTime first tries to locate a graphics importer component for the specified file based on the Macintosh file type of the file. If it is unable to locate a graphics importer component based on the Macintosh file type, GetGraphicsImporterForFile will try to locate a graphics importer component for the specified file based on the file name extension of the file.
If you have the file name, you should add the file name to the handle
data reference. If you know the file type or MIME type, you should add
this information as well. You can also specify any initialization data for the handle data reference.
How do you go about adding this information to a handle data reference? Use the handle data reference extensions. Here's the format of a data reference handle with data reference extensions:
The format of a data reference handle is:

optionally continued by a pascal string containing the file name (*not padded* - zero byte if not available). Note the filename is not really a data reference extension - QuickTime 3 will recognize any file name added to the data reference.

optionally continued by a sequence of n classic atoms, whose format is as follows (atom size and atom type fields must be big-endian):
Atom types may be any of the following:
|